import configparser
import os.path

import yaml


def get_project_path():
    cf = os.path.realpath(__file__)  # read_file.py
    cd = os.path.dirname(cf)  # caw
    cd = os.path.dirname(cd)  # futureloan
    return cd + "\\"


def read_ini(path, section, key):
    path = get_project_path() + path
    cp = configparser.ConfigParser()
    cp.read(path, encoding="utf-8")
    value = cp.get(section, key)
    return value


def read_yaml(path):
    path = get_project_path() + path
    # 打开文件，读取文件内容
    with open(path, 'r', encoding='utf-8') as f:
        c = f.read()
        # yaml提供的方法，将文件内容解析成yaml格式的 pip install PyYAML
        return yaml.load(c, Loader=yaml.FullLoader)


# 测试代码，用完可以删除
if __name__ == '__main__':
    print(read_yaml("data/register.yaml"))
    # print(read_ini("data/env.ini", "env", "url"))
